// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"server/components/models/ent/forecast"
	"server/components/models/ent/region"
	"server/components/models/ent/weather"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// WeatherCreate is the builder for creating a Weather entity.
type WeatherCreate struct {
	config
	mutation *WeatherMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetTemperature sets the "temperature" field.
func (wc *WeatherCreate) SetTemperature(f float64) *WeatherCreate {
	wc.mutation.SetTemperature(f)
	return wc
}

// SetHumidity sets the "humidity" field.
func (wc *WeatherCreate) SetHumidity(f float64) *WeatherCreate {
	wc.mutation.SetHumidity(f)
	return wc
}

// SetWindSpeed sets the "windSpeed" field.
func (wc *WeatherCreate) SetWindSpeed(f float64) *WeatherCreate {
	wc.mutation.SetWindSpeed(f)
	return wc
}

// SetNillableWindSpeed sets the "windSpeed" field if the given value is not nil.
func (wc *WeatherCreate) SetNillableWindSpeed(f *float64) *WeatherCreate {
	if f != nil {
		wc.SetWindSpeed(*f)
	}
	return wc
}

// SetWeatherCondition sets the "weatherCondition" field.
func (wc *WeatherCreate) SetWeatherCondition(value weather.WeatherCondition) *WeatherCreate {
	wc.mutation.SetWeatherCondition(value)
	return wc
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (wc *WeatherCreate) SetPrecipitationAmount(f float64) *WeatherCreate {
	wc.mutation.SetPrecipitationAmount(f)
	return wc
}

// SetNillablePrecipitationAmount sets the "precipitationAmount" field if the given value is not nil.
func (wc *WeatherCreate) SetNillablePrecipitationAmount(f *float64) *WeatherCreate {
	if f != nil {
		wc.SetPrecipitationAmount(*f)
	}
	return wc
}

// SetMeasurementDateTime sets the "measurementDateTime" field.
func (wc *WeatherCreate) SetMeasurementDateTime(t time.Time) *WeatherCreate {
	wc.mutation.SetMeasurementDateTime(t)
	return wc
}

// SetID sets the "id" field.
func (wc *WeatherCreate) SetID(i int64) *WeatherCreate {
	wc.mutation.SetID(i)
	return wc
}

// SetRegionID sets the "region" edge to the Region entity by ID.
func (wc *WeatherCreate) SetRegionID(id int64) *WeatherCreate {
	wc.mutation.SetRegionID(id)
	return wc
}

// SetNillableRegionID sets the "region" edge to the Region entity by ID if the given value is not nil.
func (wc *WeatherCreate) SetNillableRegionID(id *int64) *WeatherCreate {
	if id != nil {
		wc = wc.SetRegionID(*id)
	}
	return wc
}

// SetRegion sets the "region" edge to the Region entity.
func (wc *WeatherCreate) SetRegion(r *Region) *WeatherCreate {
	return wc.SetRegionID(r.ID)
}

// AddForecastIDs adds the "forecast" edge to the Forecast entity by IDs.
func (wc *WeatherCreate) AddForecastIDs(ids ...int64) *WeatherCreate {
	wc.mutation.AddForecastIDs(ids...)
	return wc
}

// AddForecast adds the "forecast" edges to the Forecast entity.
func (wc *WeatherCreate) AddForecast(f ...*Forecast) *WeatherCreate {
	ids := make([]int64, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return wc.AddForecastIDs(ids...)
}

// Mutation returns the WeatherMutation object of the builder.
func (wc *WeatherCreate) Mutation() *WeatherMutation {
	return wc.mutation
}

// Save creates the Weather in the database.
func (wc *WeatherCreate) Save(ctx context.Context) (*Weather, error) {
	wc.defaults()
	return withHooks(ctx, wc.sqlSave, wc.mutation, wc.hooks)
}

// SaveX calls Save and panics if Save returns an error.
func (wc *WeatherCreate) SaveX(ctx context.Context) *Weather {
	v, err := wc.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

// Exec executes the query.
func (wc *WeatherCreate) Exec(ctx context.Context) error {
	_, err := wc.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (wc *WeatherCreate) ExecX(ctx context.Context) {
	if err := wc.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (wc *WeatherCreate) defaults() {
	if _, ok := wc.mutation.WindSpeed(); !ok {
		v := weather.DefaultWindSpeed
		wc.mutation.SetWindSpeed(v)
	}
	if _, ok := wc.mutation.PrecipitationAmount(); !ok {
		v := weather.DefaultPrecipitationAmount
		wc.mutation.SetPrecipitationAmount(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (wc *WeatherCreate) check() error {
	if _, ok := wc.mutation.Temperature(); !ok {
		return &ValidationError{Name: "temperature", err: errors.New(`ent: missing required field "Weather.temperature"`)}
	}
	if _, ok := wc.mutation.Humidity(); !ok {
		return &ValidationError{Name: "humidity", err: errors.New(`ent: missing required field "Weather.humidity"`)}
	}
	if v, ok := wc.mutation.Humidity(); ok {
		if err := weather.HumidityValidator(v); err != nil {
			return &ValidationError{Name: "humidity", err: fmt.Errorf(`ent: validator failed for field "Weather.humidity": %w`, err)}
		}
	}
	if _, ok := wc.mutation.WindSpeed(); !ok {
		return &ValidationError{Name: "windSpeed", err: errors.New(`ent: missing required field "Weather.windSpeed"`)}
	}
	if v, ok := wc.mutation.WindSpeed(); ok {
		if err := weather.WindSpeedValidator(v); err != nil {
			return &ValidationError{Name: "windSpeed", err: fmt.Errorf(`ent: validator failed for field "Weather.windSpeed": %w`, err)}
		}
	}
	if _, ok := wc.mutation.WeatherCondition(); !ok {
		return &ValidationError{Name: "weatherCondition", err: errors.New(`ent: missing required field "Weather.weatherCondition"`)}
	}
	if v, ok := wc.mutation.WeatherCondition(); ok {
		if err := weather.WeatherConditionValidator(v); err != nil {
			return &ValidationError{Name: "weatherCondition", err: fmt.Errorf(`ent: validator failed for field "Weather.weatherCondition": %w`, err)}
		}
	}
	if _, ok := wc.mutation.PrecipitationAmount(); !ok {
		return &ValidationError{Name: "precipitationAmount", err: errors.New(`ent: missing required field "Weather.precipitationAmount"`)}
	}
	if v, ok := wc.mutation.PrecipitationAmount(); ok {
		if err := weather.PrecipitationAmountValidator(v); err != nil {
			return &ValidationError{Name: "precipitationAmount", err: fmt.Errorf(`ent: validator failed for field "Weather.precipitationAmount": %w`, err)}
		}
	}
	if _, ok := wc.mutation.MeasurementDateTime(); !ok {
		return &ValidationError{Name: "measurementDateTime", err: errors.New(`ent: missing required field "Weather.measurementDateTime"`)}
	}
	return nil
}

func (wc *WeatherCreate) sqlSave(ctx context.Context) (*Weather, error) {
	if err := wc.check(); err != nil {
		return nil, err
	}
	_node, _spec := wc.createSpec()
	if err := sqlgraph.CreateNode(ctx, wc.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != _node.ID {
		id := _spec.ID.Value.(int64)
		_node.ID = int64(id)
	}
	wc.mutation.id = &_node.ID
	wc.mutation.done = true
	return _node, nil
}

func (wc *WeatherCreate) createSpec() (*Weather, *sqlgraph.CreateSpec) {
	var (
		_node = &Weather{config: wc.config}
		_spec = sqlgraph.NewCreateSpec(weather.Table, sqlgraph.NewFieldSpec(weather.FieldID, field.TypeInt64))
	)
	_spec.OnConflict = wc.conflict
	if id, ok := wc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := wc.mutation.Temperature(); ok {
		_spec.SetField(weather.FieldTemperature, field.TypeFloat64, value)
		_node.Temperature = value
	}
	if value, ok := wc.mutation.Humidity(); ok {
		_spec.SetField(weather.FieldHumidity, field.TypeFloat64, value)
		_node.Humidity = value
	}
	if value, ok := wc.mutation.WindSpeed(); ok {
		_spec.SetField(weather.FieldWindSpeed, field.TypeFloat64, value)
		_node.WindSpeed = value
	}
	if value, ok := wc.mutation.WeatherCondition(); ok {
		_spec.SetField(weather.FieldWeatherCondition, field.TypeEnum, value)
		_node.WeatherCondition = value
	}
	if value, ok := wc.mutation.PrecipitationAmount(); ok {
		_spec.SetField(weather.FieldPrecipitationAmount, field.TypeFloat64, value)
		_node.PrecipitationAmount = value
	}
	if value, ok := wc.mutation.MeasurementDateTime(); ok {
		_spec.SetField(weather.FieldMeasurementDateTime, field.TypeTime, value)
		_node.MeasurementDateTime = value
	}
	if nodes := wc.mutation.RegionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   weather.RegionTable,
			Columns: []string{weather.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.weather_region = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := wc.mutation.ForecastIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   weather.ForecastTable,
			Columns: []string{weather.ForecastColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.Weather.Create().
//		SetTemperature(v).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.WeatherUpsert) {
//			SetTemperature(v+v).
//		}).
//		Exec(ctx)
func (wc *WeatherCreate) OnConflict(opts ...sql.ConflictOption) *WeatherUpsertOne {
	wc.conflict = opts
	return &WeatherUpsertOne{
		create: wc,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.Weather.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (wc *WeatherCreate) OnConflictColumns(columns ...string) *WeatherUpsertOne {
	wc.conflict = append(wc.conflict, sql.ConflictColumns(columns...))
	return &WeatherUpsertOne{
		create: wc,
	}
}

type (
	// WeatherUpsertOne is the builder for "upsert"-ing
	//  one Weather node.
	WeatherUpsertOne struct {
		create *WeatherCreate
	}

	// WeatherUpsert is the "OnConflict" setter.
	WeatherUpsert struct {
		*sql.UpdateSet
	}
)

// SetTemperature sets the "temperature" field.
func (u *WeatherUpsert) SetTemperature(v float64) *WeatherUpsert {
	u.Set(weather.FieldTemperature, v)
	return u
}

// UpdateTemperature sets the "temperature" field to the value that was provided on create.
func (u *WeatherUpsert) UpdateTemperature() *WeatherUpsert {
	u.SetExcluded(weather.FieldTemperature)
	return u
}

// AddTemperature adds v to the "temperature" field.
func (u *WeatherUpsert) AddTemperature(v float64) *WeatherUpsert {
	u.Add(weather.FieldTemperature, v)
	return u
}

// SetHumidity sets the "humidity" field.
func (u *WeatherUpsert) SetHumidity(v float64) *WeatherUpsert {
	u.Set(weather.FieldHumidity, v)
	return u
}

// UpdateHumidity sets the "humidity" field to the value that was provided on create.
func (u *WeatherUpsert) UpdateHumidity() *WeatherUpsert {
	u.SetExcluded(weather.FieldHumidity)
	return u
}

// AddHumidity adds v to the "humidity" field.
func (u *WeatherUpsert) AddHumidity(v float64) *WeatherUpsert {
	u.Add(weather.FieldHumidity, v)
	return u
}

// SetWindSpeed sets the "windSpeed" field.
func (u *WeatherUpsert) SetWindSpeed(v float64) *WeatherUpsert {
	u.Set(weather.FieldWindSpeed, v)
	return u
}

// UpdateWindSpeed sets the "windSpeed" field to the value that was provided on create.
func (u *WeatherUpsert) UpdateWindSpeed() *WeatherUpsert {
	u.SetExcluded(weather.FieldWindSpeed)
	return u
}

// AddWindSpeed adds v to the "windSpeed" field.
func (u *WeatherUpsert) AddWindSpeed(v float64) *WeatherUpsert {
	u.Add(weather.FieldWindSpeed, v)
	return u
}

// SetWeatherCondition sets the "weatherCondition" field.
func (u *WeatherUpsert) SetWeatherCondition(v weather.WeatherCondition) *WeatherUpsert {
	u.Set(weather.FieldWeatherCondition, v)
	return u
}

// UpdateWeatherCondition sets the "weatherCondition" field to the value that was provided on create.
func (u *WeatherUpsert) UpdateWeatherCondition() *WeatherUpsert {
	u.SetExcluded(weather.FieldWeatherCondition)
	return u
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (u *WeatherUpsert) SetPrecipitationAmount(v float64) *WeatherUpsert {
	u.Set(weather.FieldPrecipitationAmount, v)
	return u
}

// UpdatePrecipitationAmount sets the "precipitationAmount" field to the value that was provided on create.
func (u *WeatherUpsert) UpdatePrecipitationAmount() *WeatherUpsert {
	u.SetExcluded(weather.FieldPrecipitationAmount)
	return u
}

// AddPrecipitationAmount adds v to the "precipitationAmount" field.
func (u *WeatherUpsert) AddPrecipitationAmount(v float64) *WeatherUpsert {
	u.Add(weather.FieldPrecipitationAmount, v)
	return u
}

// SetMeasurementDateTime sets the "measurementDateTime" field.
func (u *WeatherUpsert) SetMeasurementDateTime(v time.Time) *WeatherUpsert {
	u.Set(weather.FieldMeasurementDateTime, v)
	return u
}

// UpdateMeasurementDateTime sets the "measurementDateTime" field to the value that was provided on create.
func (u *WeatherUpsert) UpdateMeasurementDateTime() *WeatherUpsert {
	u.SetExcluded(weather.FieldMeasurementDateTime)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
//	client.Weather.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(weather.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WeatherUpsertOne) UpdateNewValues() *WeatherUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		if _, exists := u.create.mutation.ID(); exists {
			s.SetIgnore(weather.FieldID)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.Weather.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *WeatherUpsertOne) Ignore() *WeatherUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *WeatherUpsertOne) DoNothing() *WeatherUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the WeatherCreate.OnConflict
// documentation for more info.
func (u *WeatherUpsertOne) Update(set func(*WeatherUpsert)) *WeatherUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&WeatherUpsert{UpdateSet: update})
	}))
	return u
}

// SetTemperature sets the "temperature" field.
func (u *WeatherUpsertOne) SetTemperature(v float64) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.SetTemperature(v)
	})
}

// AddTemperature adds v to the "temperature" field.
func (u *WeatherUpsertOne) AddTemperature(v float64) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.AddTemperature(v)
	})
}

// UpdateTemperature sets the "temperature" field to the value that was provided on create.
func (u *WeatherUpsertOne) UpdateTemperature() *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateTemperature()
	})
}

// SetHumidity sets the "humidity" field.
func (u *WeatherUpsertOne) SetHumidity(v float64) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.SetHumidity(v)
	})
}

// AddHumidity adds v to the "humidity" field.
func (u *WeatherUpsertOne) AddHumidity(v float64) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.AddHumidity(v)
	})
}

// UpdateHumidity sets the "humidity" field to the value that was provided on create.
func (u *WeatherUpsertOne) UpdateHumidity() *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateHumidity()
	})
}

// SetWindSpeed sets the "windSpeed" field.
func (u *WeatherUpsertOne) SetWindSpeed(v float64) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.SetWindSpeed(v)
	})
}

// AddWindSpeed adds v to the "windSpeed" field.
func (u *WeatherUpsertOne) AddWindSpeed(v float64) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.AddWindSpeed(v)
	})
}

// UpdateWindSpeed sets the "windSpeed" field to the value that was provided on create.
func (u *WeatherUpsertOne) UpdateWindSpeed() *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateWindSpeed()
	})
}

// SetWeatherCondition sets the "weatherCondition" field.
func (u *WeatherUpsertOne) SetWeatherCondition(v weather.WeatherCondition) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.SetWeatherCondition(v)
	})
}

// UpdateWeatherCondition sets the "weatherCondition" field to the value that was provided on create.
func (u *WeatherUpsertOne) UpdateWeatherCondition() *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateWeatherCondition()
	})
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (u *WeatherUpsertOne) SetPrecipitationAmount(v float64) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.SetPrecipitationAmount(v)
	})
}

// AddPrecipitationAmount adds v to the "precipitationAmount" field.
func (u *WeatherUpsertOne) AddPrecipitationAmount(v float64) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.AddPrecipitationAmount(v)
	})
}

// UpdatePrecipitationAmount sets the "precipitationAmount" field to the value that was provided on create.
func (u *WeatherUpsertOne) UpdatePrecipitationAmount() *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdatePrecipitationAmount()
	})
}

// SetMeasurementDateTime sets the "measurementDateTime" field.
func (u *WeatherUpsertOne) SetMeasurementDateTime(v time.Time) *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.SetMeasurementDateTime(v)
	})
}

// UpdateMeasurementDateTime sets the "measurementDateTime" field to the value that was provided on create.
func (u *WeatherUpsertOne) UpdateMeasurementDateTime() *WeatherUpsertOne {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateMeasurementDateTime()
	})
}

// Exec executes the query.
func (u *WeatherUpsertOne) Exec(ctx context.Context) error {
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for WeatherCreate.OnConflict")
	}
	return u.create.Exec(ctx)
}

// ExecX is like Exec, but panics if an error occurs.
func (u *WeatherUpsertOne) ExecX(ctx context.Context) {
	if err := u.create.Exec(ctx); err != nil {
		panic(err)
	}
}

// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *WeatherUpsertOne) ID(ctx context.Context) (id int64, err error) {
	node, err := u.create.Save(ctx)
	if err != nil {
		return id, err
	}
	return node.ID, nil
}

// IDX is like ID, but panics if an error occurs.
func (u *WeatherUpsertOne) IDX(ctx context.Context) int64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

// WeatherCreateBulk is the builder for creating many Weather entities in bulk.
type WeatherCreateBulk struct {
	config
	err      error
	builders []*WeatherCreate
	conflict []sql.ConflictOption
}

// Save creates the Weather entities in the database.
func (wcb *WeatherCreateBulk) Save(ctx context.Context) ([]*Weather, error) {
	if wcb.err != nil {
		return nil, wcb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(wcb.builders))
	nodes := make([]*Weather, len(wcb.builders))
	mutators := make([]Mutator, len(wcb.builders))
	for i := range wcb.builders {
		func(i int, root context.Context) {
			builder := wcb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*WeatherMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, wcb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = wcb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, wcb.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				if specs[i].ID.Value != nil && nodes[i].ID == 0 {
					id := specs[i].ID.Value.(int64)
					nodes[i].ID = int64(id)
				}
				mutation.done = true
				return nodes[i], nil
			})
			for i := len(builder.hooks) - 1; i >= 0; i-- {
				mut = builder.hooks[i](mut)
			}
			mutators[i] = mut
		}(i, ctx)
	}
	if len(mutators) > 0 {
		if _, err := mutators[0].Mutate(ctx, wcb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

// SaveX is like Save, but panics if an error occurs.
func (wcb *WeatherCreateBulk) SaveX(ctx context.Context) []*Weather {
	v, err := wcb.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

// Exec executes the query.
func (wcb *WeatherCreateBulk) Exec(ctx context.Context) error {
	_, err := wcb.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (wcb *WeatherCreateBulk) ExecX(ctx context.Context) {
	if err := wcb.Exec(ctx); err != nil {
		panic(err)
	}
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.Weather.CreateBulk(builders...).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.WeatherUpsert) {
//			SetTemperature(v+v).
//		}).
//		Exec(ctx)
func (wcb *WeatherCreateBulk) OnConflict(opts ...sql.ConflictOption) *WeatherUpsertBulk {
	wcb.conflict = opts
	return &WeatherUpsertBulk{
		create: wcb,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.Weather.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (wcb *WeatherCreateBulk) OnConflictColumns(columns ...string) *WeatherUpsertBulk {
	wcb.conflict = append(wcb.conflict, sql.ConflictColumns(columns...))
	return &WeatherUpsertBulk{
		create: wcb,
	}
}

// WeatherUpsertBulk is the builder for "upsert"-ing
// a bulk of Weather nodes.
type WeatherUpsertBulk struct {
	create *WeatherCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.Weather.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(weather.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WeatherUpsertBulk) UpdateNewValues() *WeatherUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		for _, b := range u.create.builders {
			if _, exists := b.mutation.ID(); exists {
				s.SetIgnore(weather.FieldID)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.Weather.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *WeatherUpsertBulk) Ignore() *WeatherUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *WeatherUpsertBulk) DoNothing() *WeatherUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the WeatherCreateBulk.OnConflict
// documentation for more info.
func (u *WeatherUpsertBulk) Update(set func(*WeatherUpsert)) *WeatherUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&WeatherUpsert{UpdateSet: update})
	}))
	return u
}

// SetTemperature sets the "temperature" field.
func (u *WeatherUpsertBulk) SetTemperature(v float64) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.SetTemperature(v)
	})
}

// AddTemperature adds v to the "temperature" field.
func (u *WeatherUpsertBulk) AddTemperature(v float64) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.AddTemperature(v)
	})
}

// UpdateTemperature sets the "temperature" field to the value that was provided on create.
func (u *WeatherUpsertBulk) UpdateTemperature() *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateTemperature()
	})
}

// SetHumidity sets the "humidity" field.
func (u *WeatherUpsertBulk) SetHumidity(v float64) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.SetHumidity(v)
	})
}

// AddHumidity adds v to the "humidity" field.
func (u *WeatherUpsertBulk) AddHumidity(v float64) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.AddHumidity(v)
	})
}

// UpdateHumidity sets the "humidity" field to the value that was provided on create.
func (u *WeatherUpsertBulk) UpdateHumidity() *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateHumidity()
	})
}

// SetWindSpeed sets the "windSpeed" field.
func (u *WeatherUpsertBulk) SetWindSpeed(v float64) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.SetWindSpeed(v)
	})
}

// AddWindSpeed adds v to the "windSpeed" field.
func (u *WeatherUpsertBulk) AddWindSpeed(v float64) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.AddWindSpeed(v)
	})
}

// UpdateWindSpeed sets the "windSpeed" field to the value that was provided on create.
func (u *WeatherUpsertBulk) UpdateWindSpeed() *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateWindSpeed()
	})
}

// SetWeatherCondition sets the "weatherCondition" field.
func (u *WeatherUpsertBulk) SetWeatherCondition(v weather.WeatherCondition) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.SetWeatherCondition(v)
	})
}

// UpdateWeatherCondition sets the "weatherCondition" field to the value that was provided on create.
func (u *WeatherUpsertBulk) UpdateWeatherCondition() *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateWeatherCondition()
	})
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (u *WeatherUpsertBulk) SetPrecipitationAmount(v float64) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.SetPrecipitationAmount(v)
	})
}

// AddPrecipitationAmount adds v to the "precipitationAmount" field.
func (u *WeatherUpsertBulk) AddPrecipitationAmount(v float64) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.AddPrecipitationAmount(v)
	})
}

// UpdatePrecipitationAmount sets the "precipitationAmount" field to the value that was provided on create.
func (u *WeatherUpsertBulk) UpdatePrecipitationAmount() *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdatePrecipitationAmount()
	})
}

// SetMeasurementDateTime sets the "measurementDateTime" field.
func (u *WeatherUpsertBulk) SetMeasurementDateTime(v time.Time) *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.SetMeasurementDateTime(v)
	})
}

// UpdateMeasurementDateTime sets the "measurementDateTime" field to the value that was provided on create.
func (u *WeatherUpsertBulk) UpdateMeasurementDateTime() *WeatherUpsertBulk {
	return u.Update(func(s *WeatherUpsert) {
		s.UpdateMeasurementDateTime()
	})
}

// Exec executes the query.
func (u *WeatherUpsertBulk) Exec(ctx context.Context) error {
	if u.create.err != nil {
		return u.create.err
	}
	for i, b := range u.create.builders {
		if len(b.conflict) != 0 {
			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the WeatherCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for WeatherCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

// ExecX is like Exec, but panics if an error occurs.
func (u *WeatherUpsertBulk) ExecX(ctx context.Context) {
	if err := u.create.Exec(ctx); err != nil {
		panic(err)
	}
}
